﻿using MediatR;
using S.Produce.Domains;
using S.Produce.Infrastructure;
using S.Produce.Read.Api.Application.Commands.ShiftCommands;

namespace S.Produce.Read.Api.Application.CommandHandlers.ShiftCommandHandlers
{
    /// <summary>
    /// 根据耳号查到转舍记录
    /// </summary>
    public class ShiftEarCommandHandler : IRequestHandler<ShiftEarCommand, List<ShiftDorm>>
    {
        private readonly IRepository<ShiftDorm> repository;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="repository"></param>
        public ShiftEarCommandHandler(IRepository<ShiftDorm> repository)
        {
            this.repository = repository;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<List<ShiftDorm>> Handle(ShiftEarCommand request, CancellationToken cancellationToken)
        {
            return await repository.SelAllAsync(x => x.Earbugles == request.EarNumber);
        }
    }
}
